#ifndef OCTTrackingApp_H
#define OCTTrackingApp_H

#define LANDMARK1 1
#define LANDMARK2 2
#define LANDMARK3 3
#define LANDMARK4 4


#include <QtGui/QMessageBox>
#include <pthread.h>

#include "AppUI/TrackingGUI.h"

#include "OCTTrackingHeader.h"

#include "OCTSource/OCTSourceSetting.h"

#include "Landmark/Landmark.h"
#include "Landmark/LandmarkPattern.h"

#include "OCTTrackingCore/OCTLandmarkLocating.h"

class OCTTrackingApp : public QMainWindow
{
Q_OBJECT
public:
  OCTTrackingApp(QWidget *parent = 0, Qt::WFlags flags = 0);
  virtual ~OCTTrackingApp();

  
private:
  Ui_MainWindow *ui;
  // original object surface
  Mat initSourceImage;
  
  // object surface gray image
  Mat graySourceImage;
  
  // object surface color image, is used for paint the oct image
  Mat colorSourceImage;
  
  // object surface color temp image, is used for recover the display of oct image
  Mat colorTempImage;
  
  Mat landmarkBlackImage;
  
  Landmark *landmark1, *landmark2, *landmark3, *landmark4;
  LandmarkPattern *landmarkPattern;
  
  OCTSourceSetting *octSource;
  
  OCTLandmarkLocating *landmarkLocating;
  
  string patternName;
  bool locationError;
  bool trackingError;
  
private:
  void initializeUI(QMainWindow *MainWindow);
  void retranslateUI(QMainWindow *MainWindow);
  void setupSlots(QMainWindow *MainWindow);
  
  void initializeTracking();
  
  void paintImage(Mat sourceImage, QLabel* target, QImage::Format format);
  bool validateLandmarkInput(QLineEdit* inputX, QLineEdit* inputY, QLineEdit* inputRange, int& x, int& y, int& r);
 
  void markPoint(Mat src, Point pt);
  void markRegion(Mat src, Point pt, int range);
  void rePaintImage();
  
  Landmark* createLandmark(Point center, int range, string fileName);
  
  void removeLandmark(Mat src, Point pt, int range);
  
  void writeInfo(const QString& text);
  
  
private slots: 
  void onLandmark1SetButtonClicked();
  void onLandmark2SetButtonClicked();
  void onLandmark3SetButtonClicked();
  void onLandmark4SetButtonClicked();
  
  void onLandmark1ClearButtonClicked();
  void onLandmark2ClearButtonClicked();
  void onLandmark3ClearButtonClicked();
  void onLandmark4ClearButtonClicked();
  
  void onLandmarkPatternListIndexChanged(int idx);
  void onLandmarkPatternSetButtonClicked();
  void onLandmarkPatternClearButtonClicked();
  
  void onInitialLocatingButtonClicked();
  void onStartTrackingButtonClicked();

};

#endif // OCTTrackingApp_H
